package org.example.exception;


import org.example.entity.AjaxResult;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.nio.file.AccessDeniedException;

@RestControllerAdvice
public class GlobalExceptionAdvice {

    @ExceptionHandler(value = LoginException.class)
    public AjaxResult handlerLoginException(LoginException ex){
        return AjaxResult.err(401, ex.getMessage());
    }

    @ExceptionHandler(value = Exception.class)
    public AjaxResult handlerLoginException(Exception ex){
        ex.printStackTrace();
        return AjaxResult.err(ex.getMessage());
    }

    @ExceptionHandler(value = BadCredentialsException.class)
    public AjaxResult handlerLoginException(BadCredentialsException ex){
        return AjaxResult.err(401,"用户名或密码不正确！");
    }

    @ExceptionHandler(value = AccessDeniedException.class)
    public AjaxResult handlerLoginException(AccessDeniedException ex){
        return AjaxResult.err(403,"你无权访问");
    }



//    @ExceptionHandler(value = NoPermsException.class)
//    public AjaxResult handlerLoginException(NoPermsException  ex){
//        return AjaxResult.err(403,ex.getMessage());
//    }

}
